[PATCH] [mlir][spirv] Fix crash in spirv-lower-abi-attributes
authorJakub Kuderski <kubak@google.com>
Fri, 13 Jan 2023 15:55:04 +0000 (10:55 -0500)
committerGianfranco Costamagna <locutusofborg@debian.org>
Thu, 7 Sep 2023 22:43:45 +0000 (00:43 +0200)
... when the are no SPIR-V env attributes.

Fixes: https://github.com/llvm/llvm-project/issues/59983
Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D141695

Gbp-Pq: Name CVE-2023-29939.patch

mlir/lib/Dialect/SPIRV/Transforms/LowerABIAttributesPass.cpp
mlir/test/Dialect/SPIRV/Transforms/abi-interface.mlir

index 263f00ef1d863e09a29352e5970dff02f80c86a2..2ef02a699296acff46eff4400ce6d71b49383014 100644 (file)
@@ -239,7 +239,12 @@ void LowerABIAttributesPass::runOnOperation() {
   spirv::ModuleOp module = getOperation();
   MLIRContext *context = &getContext();
 
-  spirv::TargetEnv targetEnv(spirv::lookupTargetEnv(module));
+  spirv::TargetEnvAttr targetEnvAttr = spirv::lookupTargetEnv(module);
+  if (!targetEnvAttr) {
+    module->emitOpError("missing SPIR-V target env attribute");
+    return signalPassFailure();
+  }
+  spirv::TargetEnv targetEnv(targetEnvAttr);
 
   SPIRVTypeConverter typeConverter(targetEnv);
 
index b6b962122345f9a9f126e2d40d1c5b7a33a54e48..7b8a7b964fed916f6b052995479c9d95fc8c181c 100644 (file)
@@ -29,3 +29,10 @@ spv.module Logical GLSL450 {
 } // end spv.module
 
 } // end module
+
+// -----
+
+module {
+// expected-error@+1 {{'spirv.module' op missing SPIR-V target env attribute}}
+spirv.module Logical GLSL450 {}
+} // end module